import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
public class OddNumbersThreadPool {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        List<Integer> numbers = new ArrayList<>();
        for (int i = 1; i <= 100; i++) {
            numbers.add(i);
        }
        ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10));
        List<Future<List<Integer>>> futures = new ArrayList<>();
        int chunkSize = 10;
        for (int i = 0; i < numbers.size(); i += chunkSize) {
            int endIndex = Math.min(i + chunkSize, numbers.size());
            List<Integer> subList = numbers.subList(i, endIndex);
            Future<List<Integer>> future = executorService.submit(() -> {
                List<Integer> oddNumbers = new ArrayList<>();
                for (int j = 0; j < subList.size(); j++) {
                    if (subList.get(j) % 2 != 0) {
                        oddNumbers.add(subList.get(j));
                        System.out.println( Thread.currentThread().getName()+oddNumbers);

                    }
                }
                return oddNumbers;
            });
            futures.add(future);
        }
        List<Integer> oddNumbers = new ArrayList<>();
        for (Future<List<Integer>> future : futures) {
            oddNumbers.addAll(future.get());
        }
        executorService.shutdown();
        executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        for (int i = 0; i < oddNumbers.size(); i++) {
        //    System.out.println(oddNumbers.get(i));
        }
    }
}